	
	import Vue from 'vue'
	import VueRouter from 'vue-router'
	
	//要告诉Vue使用VueRouter
	Vue.use(VueRouter);
	
	import Home from './components/home'
	import Menu from './components/menu'
	import Admin from './components/admin'
	import Login from './components/login'
	import Register from './components/register'
	import About from './components/about/about'
	
	import History from './components/about/history'
	import Delivery from './components/about/delivery'
	import Contact from './components/about/contact'
	import OrderingGuide from './components/about/orderingGuide'
	
	import PersonName from './components/about/contact/personName'
	import Phone from './components/about/contact/phone'
	
	
	const routes=[
		{path:'/',components:{
			default:Home,
			'OrderingGuide':OrderingGuide,
			'Delivery':Delivery,
			'History':History
			}
		},
		{path:'/Menu',component:Menu},
		{path:'/Admin',component:Admin,
//			beforeEnter:(to,from,next) => {
//			//路由判断权限,路由独享守卫
//			//判断跳转的页面
	//		if(to.path == '/Login' || to.path == '/Register'){
	//			next();
	//		}else{
//				alert("请先登录");
	//			next('/Login');
	//		}
//			}
		},
		{path:'/Login',component:Login},
		{path:'/Register',component:Register},
		//redirect设置默认显示的页面
		{path:'/About',component:About,redirect:'/about/Contact',children:[
			{path:'/about/Contact',component:Contact,redirect:'/PersonName',children:[
				{path:'/PersonName',component:PersonName},
				{path:'/Phone',component:Phone}
			]},
			{path:'/History',component:History},
			{path:'/Delivery',component:Delivery},
			{path:'/OrderingGuide',component:OrderingGuide},
		]},
		{path:'*',redirect:"/"},//当输入路径没有时重定向到home主页
	]
	
	var router=new VueRouter({
		routes,
		mode:"history",
		scrollBehavior(to,from,savedPosition){ //滚动条位置,仅针对浏览器返回
//			return {x:0,y:100} //固定位置
			if(savedPosition){
				return savedPosition;
			}else{
				return {x:0,y:0}	
			}
		}
	})
	
	//全局守卫
//	router.beforeEach((to,from,next) => {
////		alert("请先登录");
////		next();
////		console.log(to);
//		//判断跳转的页面
//		if(to.path == '/Login' || to.path == '/Register'){
//			next();
//		}else{
//			alert("请先登录");
//			next('/Login');
//		}
//		
//	})
	
	//后置钩子
//	router.afterEach((to,from) => {
//		alert("afterEach");
//	})
	
	
	export default router;
